package LeetCode.algorithms.twoSum;

import java.util.HashMap;

public class Solution {
	public static void main(String[] args) {
		int[] r = twoSum(new int[] { 3, 2, 4 }, 6);
		for (int i : r) {
			System.out.println(i);
		}
	}

	public static int[] twoSum(int[] nums, int target) {
		int[] result = new int[2];
		HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
		int len = nums.length;
		for (int i = 0; i < len; i++) {
			int s = target - nums[i];
			if (map.containsKey(nums[i])) {
				result[0] = map.get(nums[i]);
				result[1] = i;
				break;
			}
			map.put(s, i);
		}
		return result;
	}
}
